package com.example.demo.controller.usercontroller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.common.Result;
import com.example.demo.entity.GrowthRecord;
import com.example.demo.service.GrowthRecordService;
import com.example.demo.vo.GrowthRecordVO;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * (GrowthRecord)表控制层
 *
 * @author makejava
 * @since 2025-01-27 23:57:21
 */
@RestController
@RequestMapping("user/growthRecord")
@RequiredArgsConstructor
public class GrowthRecordController {
    private final GrowthRecordService growthRecordService;
    @GetMapping("childinfo")
    @Operation(description = "获取孩子列表")
    public Result<List<GrowthRecordVO>> userinfo(@RequestParam("childId") Long childId) {
        return Result.success(growthRecordService.getGrowthRecord(childId));
    }
    @PostMapping("add")
    @Operation(description = "添加成长记录")
    public Result add(@RequestBody GrowthRecord growthRecord) {
        growthRecordService.addGrowthRecord(growthRecord);
        return Result.success();
    }
    @PostMapping("del/{id}")
    @Operation(description = "删除成长记录")
    @CacheEvict(value = "child:growth", key = "#id")
    public Result del(@PathVariable String id) {
        boolean b = growthRecordService.removeById(id);
        System.out.println(b);
        return Result.success();
    }
    @PostMapping("update")
    @Operation(description = "更新成长记录")
    @CacheEvict(value = "child:growth", key = "#growthRecord.childId")
    public Result update(@RequestBody GrowthRecord growthRecord) {
        growthRecordService.updateById(growthRecord);
        return Result.success();
    }
}

